import Vue from 'vue'
import VueRouter from 'vue-router'





Vue.use(VueRouter)

const routes = [

  {
    path: '/',
    name: 'login',
    component: () => import(/* webpackChunkName: "about" */ '../views/LoginView.vue')
  },
  {
    path: '/main',
    name: '首页',
    component: () => import(/* webpackChunkName: "about" */ '../views/FistyeView.vue'),
    children: [
      {
        path: 'wuliu',
        name: ' Wuliu',
        meta: {
          title: '物流'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/WuliuView.vue'),
        
      },
      {
        path: 'driver',
        name: ' Driver',
        meta: {
          title: '司机空闲表'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/DriverView.vue'),
      },
      {
        path: 'carpay',
        name: 'Carpay',
        meta: {
          title: '车辆收费'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/CarpayView.vue'),
      },
      {
        path: 'shopgl',
        name: 'Shopgl',
        meta: {
          title: '商铺管理'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/shopglView.vue'),
      },
      {
        path: 'usergl',
        name: 'Usergl',
        meta: {
          title: '员工管理'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/UserglView.vue'),
      },
      {
        path: 'yghs',
        name: 'Yghs',
        meta: {
          title: '员工核酸'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/YGyiqingView.vue'),
      },
      {
        path: 'sjhs',
        name: 'Sjhs',
        meta: {
          title: '司机核酸'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/SJyiqingView.vue'),
      },
      {
        path: 'hwhs',
        name: 'Hwhs',
        meta: {
          title: '货物核酸'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/HWyiqingView.vue'),
      },
      {
        path: 'son',
        name: 'Sonrouter',
        meta: {
          title: '模糊查询子路由'
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/ZisonrouterView.vue'),
      }
      
    ]
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path == "/" || to.path == "/login") {
    next();
  }
  else {
    if (localStorage.getItem("token")) {
      next();
    }
    else {
      next("/login")
    }
  }

})

export default router
